var tellPhone = "";
function findUserByTellPhone() {
    var tellphone = document.getElementById("telnumber");
    var name = document.getElementById("name");
    var kind = document.getElementById("kind");
    var Balance = document.getElementById("Balance");
    var cutNum = document.getElementById("cutNum");
    var perNum = document.getElementById("perNum");
    var nuseNum = document.getElementById("nuseNum");
    var rootNum = document.getElementById("rootNum");
    var dyeNum = document.getElementById("dyeNum");
    var washNum = document.getElementById("washNum");
    var blackNum = document.getElementById("blackNum");

    var inMoney = document.getElementById("inMoney");
    var inNum = document.getElementById("inNum");
    var inNum2 = document.getElementById("inNum2");
    var inNum3 = document.getElementById("inNum3");
    var inNum4 = document.getElementById("inNum4");
    var inNum5 = document.getElementById("inNum5");
    var inNum6 = document.getElementById("inNum6");
    var inNum7 = document.getElementById("inNum7");
    var inNum8 = document.getElementById("inNum8");

    var invest = document.getElementById("invest");
    var invest1 = document.getElementById("invest1");
    var invest2 = document.getElementById("invest2");
    var invest3 = document.getElementById("invest3");
    var invest4 = document.getElementById("invest4");
    var invest5 = document.getElementById("invest5");
    var invest6 = document.getElementById("invest6");
    var invest7 = document.getElementById("invest7");
    var cost = document.getElementById("cost");
    //手机号验证
    const reg1 =/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
    if (!reg1.test(tellphone.value)) {
        name.value = "";
        kind.value = "";
        Balance.value = "";
        cutNum.value = "";
        perNum.value = "";
        nuseNum.value = "";
        rootNum.value = "";
        dyeNum.value = "";
        washNum.value = "";
        blackNum.value = "";

        invest.disabled = true;
        invest1.disabled = true;
        invest2.disabled = true;
        invest3.disabled = true;
        invest4.disabled = true;
        invest5.disabled = true;
        invest6.disabled = true;
        invest7.disabled = true;
        cost.disabled = true;
        return false;
    }
    else {


        axios.post("http://localhost:8081/user/getUserBytellPhone", {tellphone: tellphone.value}).then(res => {
            if (res.data.state) {
                var user = res.data.user;
                tellPhone = user.tellphone;
                name.value = user.username;
                var type = user.type;
                switch (type) {
                    case '0':kind.value = "剪发";break;
                    case '1':kind.value = "洗发";break;
                    case '2':kind.value = "护理";break;
                    case '3':kind.value = "补发根";break;
                    case '4':kind.value = "染发";break;
                    case '5':kind.value = "黑油";break;
                    case '6':kind.value = "烫发+剪发";break;
                    case '7':kind.value = "烫发+染发";break;
                    case '8':kind.value = "洗发+染发";break;
                    case '9':kind.value = "剪发+黑油";break;
                    case '10':kind.value = "剪发+染发";break;
                }
                Balance.value = user.invest;
                cutNum.value = user.haircut;
                perNum.value = user.perm;
                nuseNum.value = user.wash_protect;
                rootNum.value = user.hairroot;
                dyeNum.value = user.colour;
                washNum.value = user.wash;
                blackNum.value = user.black;

                invest.disabled = false;
                invest1.disabled = false;
                invest2.disabled = false;
                invest3.disabled = false;
                invest4.disabled = false;
                invest5.disabled = false;
                invest6.disabled = false;
                invest7.disabled = false;
                cost.disabled = false;

            } else {
                name.value = "";
                kind.value = "";
                Balance.value = "";
                cutNum.value = "";
                perNum.value = "";
                nuseNum.value = "";
                rootNum.value = "";
                dyeNum.value = "";
                washNum.value = "";
                blackNum.value = "";

                invest.disabled = true;
                invest1.disabled = true;
                invest2.disabled = true;
                invest3.disabled = true;
                invest4.disabled = true;
                invest5.disabled = true;
                invest6.disabled = true;
                invest7.disabled = true;
                cost.disabled = true;
                // alert(res.data.msg);
            }
        })
    }
}
function investTimes(obj) {
    var cutNum = document.getElementById("cutNum");
    var perNum = document.getElementById("perNum");
    var nuseNum = document.getElementById("nuseNum");
    var rootNum = document.getElementById("rootNum");
    var dyeNum = document.getElementById("dyeNum");
    var washNum = document.getElementById("washNum");
    var blackNum = document.getElementById("blackNum");

    var inNum = document.getElementById("inNum");
    var inNum2 = document.getElementById("inNum2");
    var inNum3 = document.getElementById("inNum3");
    var inNum4 = document.getElementById("inNum4");
    var inNum5 = document.getElementById("inNum5");
    var inNum6 = document.getElementById("inNum6");
    var inNum7 = document.getElementById("inNum7");
    if(obj === '剪发' && inNum.value === '') return false;
    if(obj === '烫发' && inNum2.value === '') return false;
    if(obj === '护理' && inNum3.value === '') return false;
    if(obj === '补发根' && inNum4.value === '') return false;
    if(obj === '染发' && inNum5.value === '') return false;
    if(obj === '洗发' && inNum6.value === '') return false;
    if(obj === '黑油' && inNum7.value === '') return false;

    var flag = confirm("确定充值"+obj+"次数？");
    if(flag){
        if(obj === '剪发'){
            cutNum.value = cutNum.value*1 + inNum.value*1;
            inNum.value = "";
        }
        if(obj === '烫发'){
            perNum.value = perNum.value*1 + inNum2.value*1;
            inNum2.value = "";
        }
        if(obj === '护理'){
            nuseNum.value = nuseNum.value*1 + inNum3.value*1;
            inNum3.value = "";
        }
        if(obj === '补发根'){
            rootNum.value = rootNum.value*1 + inNum4.value*1;
            inNum4.value = "";
        }
        if(obj === '染发'){
            dyeNum.value = dyeNum.value*1 + inNum5.value*1;
            inNum5.value = "";
        }
        if(obj === '洗发'){
            washNum.value = washNum.value*1 + inNum6.value*1;
            inNum6.value = "";
        }
        if(obj === '黑油'){
            blackNum.value = blackNum.value*1 + inNum7.value*1;
            inNum7.value = "";
        }
    }

}
function investCard() {
    var Balance = document.getElementById("Balance");
    var inMoney = document.getElementById("inMoney");
    var telnumber = document.getElementById("telnumber");
    if(inMoney.value === ""){
        return false;
    }else{
        var flag = confirm("确定充值？");
        if(flag) {
            axios.post("http://localhost:8081/user/investCard", {
                investCard: inMoney.value,
                tellphone: telnumber.value
            }).then(res => {
                if (res.data.state) {
                    Balance.value = Balance.value * 1.00 + inMoney.value * 1.00;
                    inMoney.value = "";
                    alert(res.data.msg);
                } else {
                    inMoney.value = "";
                    alert(res.data.msg);
                }
            })
        }
    }
}
function cost() {
    var inNum8 = document.getElementById("inNum8");
    if(inNum8.value === "")return false;
    var flag = confirm("请核对上面信息，确定消费？");
    if(flag){
        var cutNum = document.getElementById("cutNum");
        var perNum = document.getElementById("perNum");
        var nuseNum = document.getElementById("nuseNum");
        var rootNum = document.getElementById("rootNum");
        var dyeNum = document.getElementById("dyeNum");
        var washNum = document.getElementById("washNum");
        var blackNum = document.getElementById("blackNum");

        axios.post("http://localhost:8081/user/investTimes", {
            tellphone:tellPhone,
            cutNum:cutNum.value,
            perNum:perNum.value,
            nuseNum:nuseNum.value,
            rootNum:rootNum.value,
            dyeNum:dyeNum.value,
            washNum:washNum.value,
            blackNum:blackNum.value,
            invest:inNum8.value
        }).then(res => {
            alert(res.data.msg);
            if(res.data.state){
                inNum8.value = "";
            }
        })

    }




}
